package com.gjy.redis.util;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-07-04 20:07:16
 */
public class RedissonUtil {

    /*private static final String REDIS_HOST_PORT = "192.168.253.142:6379";
    private static final String REDIS_HOST = "192.168.253.142";*/
    private static final String REDIS_HOST_PORT = "127.0.0.1:6379";
    private static final String REDIS_HOST = "127.0.0.1";

    public static Jedis jedisBasic() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(200);
        config.setMaxTotal(300);
        config.setTestOnBorrow(false);
        config.setTestOnReturn(false);
        JedisPool pool = new JedisPool(config, REDIS_HOST, 6379, 3000);
        return pool.getResource();
    }

    public static RedissonClient redissonBasic() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + REDIS_HOST_PORT);
        return Redisson.create(config);
    }

    public static RedissonClient redisson() {
        Config config = new Config();
        /*config.useSingleServer().setPassword("default:Ad823*&fhHF3%62(*j")
                .setAddress("redis://r-bp1s54v02vs3n90dv1pd.redis.rds.aliyuncs.com:9559");*/
        config.useSingleServer().setAddress("redis://" + REDIS_HOST_PORT);
        config.setLockWatchdogTimeout(60000);// 设置看门狗的超时时间，单位毫秒
        return Redisson.create(config);
    }

    public static RedissonClient redisson2() {
        Config config = new Config();
        //config.useSingleServer().setAddress("redis://192.168.200.152:6379");
        config.useSingleServer().setAddress("redis://" + REDIS_HOST_PORT);
        return Redisson.create(config);
    }

    public static Jedis jedis() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(200);
        config.setMaxTotal(300);
        config.setTestOnBorrow(false);
        config.setTestOnReturn(false);
        //String host = "r-bp1s54v02vs3n90dv1pd.redis.rds.aliyuncs.com";
        //String password = "default:Ad823*&fhHF3%62(*j";
        JedisPool pool = new JedisPool(config, REDIS_HOST, 9559, 3000);
        return pool.getResource();
    }

    public static Jedis jedis2() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(200);
        config.setMaxTotal(300);
        config.setTestOnBorrow(false);
        config.setTestOnReturn(false);
        JedisPool pool = new JedisPool(config, REDIS_HOST, 6379, 3000);
        return pool.getResource();
    }
}
